package com.xtpt.disaster.service.impl;

import com.xtpt.disaster.bean.DbnodeInfo;
import com.xtpt.disaster.bean.NodeInfo;
import com.xtpt.disaster.common.PropertyConfig;
import com.xtpt.disaster.common.SQLServer.SQLServerCommandGenerator;
import com.xtpt.disaster.service.NodeInfoManageService;
import com.xtpt.disaster.service.SQLServerBackupService;
import com.xtpt.disaster.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author jack_xin
 * @ClassName SQLServerBackupServiceImpl
 * @Desc TODO
 * @date 2021年12月06日 15:33
 * @Version TODO
 */
public class SQLServerBackupServiceImpl implements SQLServerBackupService {
    @Autowired
    NodeInfoManageService nodeInfoManageService;

    @Autowired
    PropertyConfig config;

    @Override
    public boolean backupSQLServer(DbnodeInfo dbnodeInfo) {
        String instanceName = dbnodeInfo.getNodeDbServiceName();
        Long nodeId = dbnodeInfo.getNodeId();
        NodeInfo client = nodeInfoManageService.selectById(nodeId);

        String dbName = dbnodeInfo.getNodeDbName();
        String dbUsername = dbnodeInfo.getNodeDbUsername();
        String dbPasswd = dbnodeInfo.getNodeDbPassword();
        String dbBackupRootPath = dbnodeInfo.getNodeDbBackupPath();
        String fileName = dbName + "_" + TimeUtil.dateToString(new Date());
        String filePath = dbBackupRootPath + fileName;

        //生成Transact-SQL备份命令
        String transacCommand = SQLServerCommandGenerator.BackupCommand(dbnodeInfo, fileName);
        String command = "sqlcmd -S" + instanceName + " -U" + dbUsername + " -P" + dbPasswd + " -Q " + transacCommand;




        return false;
    }
}
